package com.lykj.modules.shop.service.impl;

import com.lykj.modules.shop.entity.UserBill;
import com.lykj.modules.shop.excel.UserBillExcel;
import com.lykj.modules.shop.vo.UserBillVO;
import com.lykj.modules.shop.mapper.UserBillMapper;
import com.lykj.modules.shop.service.UserBillService;
import com.lykj.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.math.BigDecimal;
import java.util.List;

/**
 * 用户账单表 服务实现类
 *
 * @author cxl
 * @since 2022-01-14
 */
@Service
public class UserBillServiceImpl extends BaseServiceImpl<UserBillMapper, UserBill> implements UserBillService {

	@Override
	public IPage<UserBillVO> selectUserBillPage(IPage<UserBillVO> page, UserBillVO userBill) {
		return page.setRecords(baseMapper.selectUserBillPage(page, userBill));
	}

	/**
	 * 增加交易记录
	 *
	 * @param tenantId
	 * @param userId
	 * @param otherUserId
	 * @param linkId
	 * @param pm
	 * @param number
	 * @param service
	 * @param title
	 * @param category
	 * @param type
//	 * @param balance
	 * @param remark
	 */
	@Override
	public void insertBill(String tenantId,
						   Long userId,
						   Long otherUserId,
						   Long linkId,
						   int pm,
						   BigDecimal number,
						   BigDecimal service,
						   String title,
						   int category,
						   int type,
//						   BigDecimal balance,
						   String remark) {
		UserBill userBill = new UserBill();
		userBill.setTenantId(tenantId);
		userBill.setUserId(userId);
		userBill.setOtherUserId(otherUserId);
		userBill.setLinkId(linkId);
		userBill.setPm(pm);//0转出1转入
		userBill.setNumber(number);
		userBill.setService(service);
		if(category==0 && type==3) {
			userBill.setActual(number.subtract(service));
		}else{
			userBill.setActual(number.add(service));
		}
		userBill.setTitle(title);
		userBill.setCategory(category);//0现金1积分2贡献值
		userBill.setType(type);//0增加1减少2奖励3兑换4充值5提现6购物7转账8红包9收益10运费
//		userBill.setBalance(balance);
		userBill.setRemark(remark);
		this.save(userBill);
	}

	@Override
	public List<UserBillExcel> export(UserBillVO userBill){
		return baseMapper.export(userBill);
	}
}
